Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        CreateNewFRM.Show()
        Me.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Try
            a = LstRecent.Items.Item(LstRecent.SelectedIndex)
            FullScreen.Filename = a
            FullScreen.Show()
            'Reorganize()
            LoadRecent()
        Catch ex As Exception
            Button4.Enabled = False
        End Try
    End Sub
    Public Sub Reorganize()
        Dim lst As New List(Of String)
        Dim dir As String = My.Application.Info.DirectoryPath & "/rec.txt"
        a = My.Computer.FileSystem.FileExists(dir)
        If a = True Then
            f = My.Computer.FileSystem.ReadAllText(dir)
            If f = "" Then
                Exit Sub
            End If
            Try
                Do While Len(f) > 1
                    pos1 = InStr(f, ",")
                    itm = Mid(f, 1, pos1 - 1)
                    If My.Computer.FileSystem.FileExists(itm) = False Then
                        GoTo 50
                    End If
                    lst.Add(itm)
50:                 f = Mid(f, pos1 + 1)
                Loop
            Catch ex As Exception

            End Try
        Else : My.Computer.FileSystem.WriteAllText(dir, "", False)

        End If
        LoadRecent()
        selected = LstRecent.SelectedIndex
        item = lst.Item(selected)

        lst.Insert(0, item)
        lst.RemoveAt(selected)
        Dim s As String = ""
        For ii = 1 To lst.Count
            s = s & lst.Item(lst.Count - ii) & ","
        Next
        My.Computer.FileSystem.WriteAllText(dir, s, False)

        LoadRecent()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim a As DialogResult

        a = open1.ShowDialog()
        If a = Windows.Forms.DialogResult.Cancel Then
            Exit Sub
        End If
        FullScreen.Filename = open1.FileName
        FullScreen.Show()

        Dim lst As New List(Of String)
        Dim dir As String = My.Application.Info.DirectoryPath & "/rec.txt"
        a = My.Computer.FileSystem.FileExists(dir)
        If a = True Then
            f = My.Computer.FileSystem.ReadAllText(dir)
            If f = "" Then

            End If
            Try
                Do While Len(f) > 1
                    pos1 = InStr(f, ",")
                    itm = Mid(f, 1, pos1 - 1)
                    If My.Computer.FileSystem.FileExists(itm) = False Then
                        GoTo 50
                    End If
                    lst.Add(itm)
50:                 f = Mid(f, pos1 + 1)
                Loop
                Dim bl As Boolean = False
                For xx = 1 To lst.Count
                    If open1.FileName = lst.Item(xx - 1) Then
                        bl = True
                    End If
                Next
                If bl = False Then
                    My.Computer.FileSystem.WriteAllText(dir, open1.FileName & ",", True)
                End If
            Catch ex As Exception

            End Try
        Else : My.Computer.FileSystem.WriteAllText(dir, "", False)
        End If
        LoadRecent()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblversion.Text = My.Application.Info.Version.Major & "." & My.Application.Info.Version.Minor & "." & My.Application.Info.Version.Build & "." & My.Application.Info.Version.Revision
        Try
            Dim bmp As New Bitmap(Me.Width, Me.Height)
            Dim g As Graphics = Graphics.FromImage(bmp)
            Dim path As New Drawing2D.GraphicsPath
            path.AddRectangle(New Rectangle(0, 0, Me.Width, Me.Height))
            Dim b1 As New Drawing2D.PathGradientBrush(path)
            Dim c1 As New Drawing2D.ColorBlend
            c1.Colors = New Color() {GetColor(), GetColor(), GetColor(), GetColor()}
            c1.Positions = New Single() {0.0, 0.3, 0.6, 1.0}
            b1.InterpolationColors = c1
            b1.CenterPoint = New PointF(0, Me.Height)
            g.FillRectangle(b1, New Rectangle(0, 0, Me.Width, Me.Height))
            LoadRecent()
            Me.BackgroundImage = bmp
        Catch ex As Exception
            MsgBox("An Error Occured:" & (Chr(13)) & ex.Message, MsgBoxStyle.Critical, "Error...")

        End Try
    End Sub
    Public Sub LoadRecent()
        Dim lst As New List(Of String)
        Dim dir As String = My.Application.Info.DirectoryPath & "/rec.txt"
        a = My.Computer.FileSystem.FileExists(dir)
        If a = True Then
            f = My.Computer.FileSystem.ReadAllText(dir)
            If f = "" Then
                Exit Sub
            End If
            Try
                Do While Len(f) > 1
                    pos1 = InStr(f, ",")
                    itm = Mid(f, 1, pos1 - 1)
                    If My.Computer.FileSystem.FileExists(itm) = False Then
                        GoTo 50
                    End If
                    lst.Add(itm)
50:                 f = Mid(f, pos1 + 1)
                Loop
                LstRecent.Items.Clear()
                For xx = 1 To lst.Count
                    LstRecent.Items.Add(lst.Item(lst.Count - xx))
                Next
            Catch ex As Exception

            End Try
        Else : My.Computer.FileSystem.WriteAllText(dir, "", False)

        End If
    End Sub

    Public Function GetColor() As Color
        Dim c As New Color
        Randomize(Now.Second)
        Dim r As New Random(Rnd(Now.Millisecond) * 100)
        c = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256))
        Return c
    End Function

    Private Sub LstRecent_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstRecent.SelectedIndexChanged
        If LstRecent.SelectedItems.Count < 1 Then
            Button4.Enabled = False
            Exit Sub
        End If
        Button4.Enabled = True
    End Sub
End Class
